package cn.ly.recursion.factorial;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Factorial {
	
	static int inputNum;
	public static void main(String[] args) throws IOException {
		System.out.println("Enter a number:");
		inputNum = getInputNum();
		System.out.println(countFactorial(inputNum));
		
	}
	
	public static int getInputNum() throws IOException{
		InputStreamReader reader = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(reader);
		return Integer.parseInt(br.readLine());
	}
	
	public static int countFactorial(int n){
		//1、退出条件当n=0时，返回 1 ，0! = 1 0的阶乘为1
		if(n == 0){
			return 1;
		}else{//2、否则继续递归调用
			return n * countFactorial(n-1);
		}
	}
	
}
